﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using dhDataAcess.produceLinq;
using dhDataAcess.dataAcess.produceDataSetTableAdapters;
using dhDataAcess.dataAcess;

namespace dhDataAcess.produceDAL
{
  public   class packStockInMasterDAL
    {
        string  tableName = "packStockInMaster";
        private SqlTransaction tran = null;
        private SqlConnection conn = null;
        public packStockInMasterDAL(SqlTransaction _transaction, SqlConnection _conn)
        {
            tran = _transaction ;
            conn = _conn;
        }
        /// <summary>
        /// 插入包装入库主表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int packStockInMasterInsert(packStockInMasterModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
           // string insertstr = "insert into pbomMaster (mark,updateUser,updateDate,createUser,createDate,checkDate,spr,zbr,awgight,bweight,machineType,custNum,pname) values(@mark,@updateUser,@updateDate,@createUser,@createDate,@checkDate,@spr,@zbr,@awgight,@bweight,@machineType,@custNum,@pname)";
            string insertstr = baseBLL.dTableColumnRead.insertSqlStr(tableName).ToString();
            SqlParameter[] para = {
                                        new SqlParameter ("@mark",row .mark ),
                                        new SqlParameter ("@updateUser",row .updateUser ),
                                        new SqlParameter ("@updateDate",row .updateDate ),
                                        new SqlParameter ("@createDate",row .createDate ),
                                        new SqlParameter ("@createUser",row .createUser ),
                                        new SqlParameter ("@billStatus",row .billStatus ),
                                        new SqlParameter ("@billDate",row .billDate ),
                                        new SqlParameter ("@stockName",row .stockName ),
                                        new SqlParameter ("@workername",row .workername ),
                                        new SqlParameter ("@deptNum",row .deptNum ),
                                        new SqlParameter ("@billNo",row .billNo),
                                        new SqlParameter ("@Status",row .Status )
                                    };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = insertstr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 存储过程插入包装入库主表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int packStockInMasterInsertII(produceDataSet.packStockInMasterDataTable masterTable, produceDataSet.packStockInDetailDataTable detailTable)
        {
            DataTable dt = new DataTable();

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            string insertstr = "packStockInUpdate";
            SqlParameter par = new SqlParameter("@packStockMaster", masterTable);
            par.SqlDbType = SqlDbType.Structured;
            par.TypeName = "packStockInMaster";
            cmd.Parameters.Add(par);


            SqlParameter par1 = new SqlParameter("@packStockDetail", detailTable);
            par1.SqlDbType = SqlDbType.Structured;
            par1.TypeName = "packStockInDetail";
            cmd.Parameters.Add(par1);

            cmd.CommandText = insertstr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 更新包装入库主表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int packStockInMasterUpdate(packStockInMasterModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string updatestr = baseBLL.dTableColumnRead.updateSqlStr(tableName).ToString();
            SqlParameter[] para = {
                                        new SqlParameter ("@mark",row .mark ),
                                        new SqlParameter ("@updateUser",row .updateUser ),
                                        new SqlParameter ("@updateDate",row .updateDate ),
                                        new SqlParameter ("@createDate",row .createDate ),
                                        new SqlParameter ("@createUser",row .createUser ),
                                        new SqlParameter ("@billStatus",row .billStatus ),
                                        new SqlParameter ("@billDate",row .billDate ),
                                        new SqlParameter ("@stockName",row .stockName ),
                                        new SqlParameter ("@workername",row .workername ),
                                        new SqlParameter ("@deptNum",row .deptNum ),
                                        new SqlParameter ("@billNo",row .billNo),
                                        new SqlParameter ("@Status",row .Status )
                                    };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = updatestr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 删除一行包装入库主表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int packStockInMasterDel(string billNo)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string deletestr = baseBLL.dTableColumnRead.delSqlStr (tableName).ToString();
            SqlParameter[] para = {
                                     
                                        new SqlParameter ("@billNo",billNo )
                                   };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = deletestr ;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 删除一行包装入库主表更新库存数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int packStockInDel(string billNo)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter[] para = {
                                     
                                        new SqlParameter ("@billNo",billNo )
                                   };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = "packStockInDel";
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
    }
}
